package itheima.dao;


import itheima.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@SuppressWarnings("all")
public interface UserMapper {

    //查询所有
    @Results({

            @Result(property = "id",column = "id" ,id = true),
            @Result(property = "birthDayYa" ,column = "birthday"),
            @Result(property = "add" ,column = "address"),

            @Result(property = "userInfo",
                    column = "id",
                    one = @One(select = "itheima.dao.UserInfoMapper.selectInfoById")),
            @Result(property = "orders",
                    column = "id",
                    many = @Many(select = "itheima.dao.OrderMapper.selectOrderById"))

    })
    @Select("select * from t_user")
    List<User> selectAll();

    //根据id查询

    @Select("select * from t_user where id = #{id}")
    User selectById(@Param("id") Integer id);

    //增加一条数据

    @SelectKey(keyProperty = "id",keyColumn = "id",before = false,resultType = int.class,statement = "select LAST_INSERT_ID()")
    @Insert("insert into t_user values(null,#{username},#{birthDayYa},#{sex},#{add})")
    int insert(User user);


    //删除一条数据

    @Delete("delete from t_user where id = #{id}")
    int delete(@Param("id") Integer id);

    //修改一条数据

    @Update("update t_user set username = #{username},birthday = #{birthday},sex = #{sex},address = #{address} " +
            "where id =#{id}")
    int update(User user);




}
